home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
- Newsgroups: comp.lang.c++
- Subject: Re: Q: implicit converstion - error?
- Date: Mon, 29 Jan 1996 13:22:02 GMT
- Organization: Pivotal Technologies
- Message-ID: <310cc2a1.11393601@news.compuserve.com>
- References: <gibsonDLr0rs.AEB@netcom.com>
- NNTP-Posting-Host: hd07-006.compuserve.com
- X-Newsreader: Forte Agent .99c/16.141
-
- gibson@netcom.com (Bob Gibson) wrote:
-
- > A friend showed me a compile error that I was able to recreate
- >with the following simple example:
- >
- >--
- >void test( const char * * ppc )
- >{
- > cout << '"' << *ppc << '"' << endl;
- >}
- >
- >int main()
- >{
- > char * msg = "Example message";
- > char * * p = &msg;
- >
- > test( ppc ); // <- Error
- > test( &msg ); // <- Error
- >
- >}
- >--
- > OK. Here's the problem. The compiler complains that a
- >"char * *" can't / won't be converted to a "const char * *".
- >I don't understand the proglem. If the function signature
- >says that it will treat the "char * *" in such a was as to
- >not change the chars' to which the pointer point, what's
- >the problem?
- >
-
- Conversion from char** -> const char ** is not
- allowed, because it is potentially unsafe. Consider
- the following code:
-
- --------------------------------------------------
-
- const char c_ch;
-
- const char **pp_c_ch;
- char *p_ch;
-
- pp_c_ch = &p_ch; /* OK _if_ char** -> const char ** allowed */
- *pp_c_ch = &c_ch; /* allowed - assigning &<const char> to const char*
- */
- /* p_ch now points at c_ch */
- *p_ch = 'X'; /* OOPS, modified c_ch! */
-
- ---------------------------------------------------
-
-
- >Thanks in advance
- >
- >Bob
- >--
- >O.J. Verdict - The best innocence money can buy
- >
- >Bob Gibson -- gibson@netcom.com
-
- John
- -----------------------------------------------------------------
- John Bain
- johnb@pivotal-dm.ccmail.compuserve.com
- -----------------------------------------------------------------
-
-